package cn.ecpay.unionpay.settle.dao;

import cn.ecpay.unionpay.settle.entity.db.TPvLaiZhangNotify;
import org.rex.DB;
import org.rex.db.exception.DBException;
import org.springframework.stereotype.Repository;

/**
 * 来账
 * Created by zhaoyanzeng on 2018/12/11.
 */
@Repository
public class LaizhangDao {

    public void insert(TPvLaiZhangNotify laiZhangNotify) throws DBException {
        String sql = "INSERT INTO T_PV_LAI_ZHANG_NOTIFY" +
                "(ID,TXN_NO,TXN_TYPE,ACQ_INS_CODE,TXN_DATE,PAYER_ACCT_NO,PAYER_ACCT_NAME,payee_Acct_No," +
                "payee_Acct_NAME,CURRENCY_CODE,txn_Amt,payee_Acct_Bal,acct_Date,CREATE_TIME,REMARK,NOTIFY_VALIDATE) " +
                "VALUES" +
                "(#{id},#{txnNo},#{txnType},#{acqInsCode},#{txnDate},#{payerAcctNo},#{payerAcctName},#{payeeAcctNo}," +
                "#{payeeAcctName},#{currencyCode},#{txnAmt},#{payeeAcctBal},#{acctDate},#{createTime},#{remark},#{notifyValidate})";
        DB.update(sql, laiZhangNotify);
    }

    /**
     * 根据ID获取交易信息
     *
     * @param id
     * @return
     * @throws DBException
     */
    public TPvLaiZhangNotify findById(String id) throws DBException {
        String sql = "SELECT * FROM T_PV_LAI_ZHANG_NOTIFY WHERE ID=?";
        return DB.get(sql, new Object[]{id}, TPvLaiZhangNotify.class);
    }

    /**
     * 根据流水号获取交易信息
     *
     * @param txnNo
     * @return
     * @throws DBException
     */
    public TPvLaiZhangNotify findByTxnNo(String txnNo) throws DBException {
        String sql = "SELECT * FROM T_PV_LAI_ZHANG_NOTIFY WHERE TXN_NO=?";
        return DB.get(sql, new Object[]{txnNo}, TPvLaiZhangNotify.class);
    }

}
